home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Utilities / Type1Manager / src / global.h < prev    next >
C/C++ Source or Header  |  1996-07-12  |  52KB  |  1,614 lines

  1. /**
  2.  * AMISH NOTE:
  3.  * double is used everywhere instead of float
  4.  * so the following is not necessary:
  5.  * #define float double
  6.  **/
  7.  
  8.  
  9. #ifdef MATHIEEE
  10. #include <mieeedoub.h>
  11. #endif
  12.  
  13. #ifdef MATH881
  14. #include <m68881.h>
  15. #endif
  16.  
  17. #ifdef MATHSTANDARD
  18. #include <math.h>
  19. #endif
  20.  
  21. #include <string.h>
  22.  
  23. #include "myfontstruct.h"
  24. #include "fontfilest.h"
  25.  
  26. extern int _FPERR;
  27. void __stdargs _CXFERR(int code);
  28.  
  29.  
  30. /*********
  31.  * t1stdio.H
  32.  *********/
  33.  
  34. typedef struct F_FILE
  35. {
  36.     unsigned char *fbuf;
  37.     int fbuflen;
  38.     int curpos;
  39. } F_FILE;
  40.  
  41.  
  42. /* defines for flags */
  43. #define UNGOTTENC (0x01)
  44. #define FIOEOF    (0x80)
  45. #define FIOERROR  (0x40)
  46.  
  47. #ifndef EOF
  48. #define EOF (-1)        /* end of file */
  49. #endif
  50.  
  51. #define F_BUFSIZ (512)
  52.  
  53.  
  54. #define T1getc(f)            T1Getc(f)
  55. #define T1ungetc(c,f)        T1Ungetc(c,f)
  56. #define T1fgetc(f)            T1Getc(f)
  57. #define T1fread(a,b,c,d)    T1Read(a,b,c,d)
  58.  
  59.  
  60. /*********
  61.  * UTIL.H
  62.  *********/
  63. #ifndef boolean
  64. typedef int boolean;
  65. #endif
  66.  
  67. #ifndef TRUE
  68. #define TRUE (1)
  69. #endif
  70.  
  71. #ifndef FALSE
  72. #define FALSE (0)
  73. #endif
  74.  
  75. /***================================================================***/
  76. /* Portable definitions for 2's complement machines.
  77.  * NOTE: These really should be based on PostScript types,
  78.  * for example, sizeof(ps_integer), or sizeof(ps_unsigned)
  79.  */
  80. #define MAX_ULONG             (~(unsigned long)(0))
  81. /* This code is portable, assuming K&R C and 2's complement arithmetic */
  82. #define MAX_INTEGER      \
  83.      ((long)((((unsigned long) 1)<<(sizeof(unsigned long)*8-1))-1))
  84. #define MIN_INTEGER           ((-MAX_INTEGER)-1)
  85.  
  86. #define MAX_ARRAY_CNT         (65535)
  87. #define MAX_DICT_CNT          (65535)
  88. #define MAX_STRING_LEN        (65535)
  89. #define MAX_NAME_LEN          (128)
  90.  
  91. /* this is the size of memory allocated for reading fonts */
  92.  
  93. #define VM_SIZE               (50*1024)
  94. /***================================================================***/
  95.  
  96. #ifndef MIN
  97. #define   MIN(a,b)   (((a)<(b)) ? a : b )
  98. #endif
  99.  
  100. /***================================================================***/
  101. /*  Routines for managing virtual memory                              */
  102. /***================================================================***/
  103. extern long vm_free;
  104. extern long vm_size;
  105. extern char *vm_next;
  106.  
  107. /***================================================================***/
  108. /*  Macros for managing virtual memory                                */
  109. /***================================================================***/
  110. #define vm_next_byte()  (vm_next)
  111. #define vm_free_bytes()  (vm_free)
  112. #define vm_avail(B)     (B <= vm_free)
  113.  
  114.  
  115.  
  116. /***================================================================***/
  117. /* Types of PostScript objects */
  118. /***================================================================***/
  119. #define OBJ_INTEGER    (0)
  120. #define OBJ_REAL       (1)
  121. #define OBJ_BOOLEAN    (2)
  122. #define OBJ_ARRAY      (3)
  123. #define OBJ_STRING     (4)
  124. #define OBJ_NAME       (5)
  125. #define OBJ_FILE       (6)
  126. #define OBJ_ENCODING   (7)
  127.  
  128. /***================================================================***/
  129. /* Value of PostScript objects */
  130. /***================================================================***/
  131. typedef union ps_value
  132. {
  133.     char *valueP;        /* value pointer for unspecified type */
  134.     int value;        /* value for unspecified type         */
  135.     int integer;        /* when type is OBJ_INTEGER           */
  136.     double real;        /* when type is OBJ_REAL              */
  137.     int boolean;        /* when type is OBJ_BOOLEAN           */
  138.     struct ps_obj *arrayP;    /* when type is OBJ_ARRAY             */
  139.     unsigned char *stringP;    /* when type is OBJ_STRING            */
  140.     const char *nameP;    /* when type is OBJ_NAME              */
  141.     F_FILE *fileP;        /* when type is OBJ_FILE              */
  142. }
  143. psvalue;
  144.  
  145. /***================================================================***/
  146. /* Definition of a PostScript object */
  147. /***================================================================***/
  148. typedef struct ps_obj
  149. {
  150.     char type;
  151.     char unused;
  152.     unsigned short len;
  153.     union ps_value data;
  154. } psobj;
  155.  
  156. /***================================================================***/
  157. /*     Definition of a PostScript Dictionary Entry */
  158. /***================================================================***/
  159. typedef struct ps_dict
  160. {
  161.     psobj key;
  162.     psobj value;
  163. } psdict;
  164.  
  165. /***================================================================***/
  166. /* Macros for testing type of PostScript objects */
  167. /***================================================================***/
  168. #define objIsInteger(o)          ((o).type == OBJ_INTEGER)
  169. #define objIsReal(o)             ((o).type == OBJ_REAL)
  170. #define objIsBoolean(o)          ((o).type == OBJ_BOOLEAN)
  171. #define objIsArray(o)            ((o).type == OBJ_ARRAY)
  172. #define objIsString(o)           ((o).type == OBJ_STRING)
  173. #define objIsName(o)             ((o).type == OBJ_NAME)
  174. #define objIsFile(o)             ((o).type == OBJ_FILE)
  175.  
  176. /***================================================================***/
  177. /* Macros for setting type of PostScript objects */
  178. /***================================================================***/
  179. #define objSetInteger(o)         ((o).type = OBJ_INTEGER)
  180. #define objSetReal(o)            ((o).type = OBJ_REAL)
  181. #define objSetBoolean(o)         ((o).type = OBJ_BOOLEAN)
  182. #define objSetArray(o)           ((o).type = OBJ_ARRAY)
  183. #define objSetString(o)          ((o).type = OBJ_STRING)
  184. #define objSetName(o)            ((o).type = OBJ_NAME)
  185. #define objSetFile(o)            ((o).type = OBJ_FILE)
  186.  
  187. /***================================================================***/
  188. /* Macros for testing type of PostScript objects (pointer access) */
  189. /***================================================================***/
  190. #define objPIsInteger(o)         ((o)->type == OBJ_INTEGER)
  191. #define objPIsReal(o)            ((o)->type == OBJ_REAL)
  192. #define objPIsBoolean(o)         ((o)->type == OBJ_BOOLEAN)
  193. #define objPIsArray(o)           ((o)->type == OBJ_ARRAY)
  194. #define objPIsString(o)          ((o)->type == OBJ_STRING)
  195. #define objPIsName(o)            ((o)->type == OBJ_NAME)
  196. #define objPIsFile(o)            ((o)->type == OBJ_FILE)
  197.  
  198. /***================================================================***/
  199. /* Macros for setting type of PostScript objects (pointer access) */
  200. /***================================================================***/
  201. #define objPSetInteger(o)        ((o)->type = OBJ_INTEGER)
  202. #define objPSetReal(o)           ((o)->type = OBJ_REAL)
  203. #define objPSetBoolean(o)        ((o)->type = OBJ_BOOLEAN)
  204. #define objPSetArray(o)          ((o)->type = OBJ_ARRAY)
  205. #define objPSetString(o)         ((o)->type = OBJ_STRING)
  206. #define objPSetName(o)           ((o)->type = OBJ_NAME)
  207. #define objPSetFile(o)           ((o)->type = OBJ_FILE)
  208.  
  209.  
  210.  
  211. /*********
  212.  * BLUES.H
  213.  *********/
  214.  
  215. #define TOPLEFT 1
  216. #define BOTTOMRIGHT 2
  217.  
  218. #define NUMBLUEVALUES 14
  219. #define NUMOTHERBLUES 10
  220. #define NUMFAMILYBLUES 14
  221. #define NUMFAMILYOTHERBLUES 10
  222. #define NUMSTEMSNAPH 12
  223. #define NUMSTEMSNAPV 12
  224. #define NUMSTDHW 1
  225. #define NUMSTDVW 1
  226.  
  227. #define DEFAULTBOLDSTEMWIDTH 2.0
  228.  
  229. #define MAXALIGNMENTZONES ((NUMBLUEVALUES+NUMOTHERBLUES)/2)
  230. #define DEFAULTBLUESCALE 0.039625
  231. #define DEFAULTBLUESHIFT 7
  232. #define DEFAULTBLUEFUZZ 1
  233. #define DEFAULTSTDHW 0
  234. #define DEFAULTSTDVW 0
  235. #define DEFAULTFORCEBOLD FALSE
  236. #define DEFAULTLANGUAGEGROUP 0
  237. #define DEFAULTRNDSTEMUP FALSE
  238. #define DEFAULTLENIV 4
  239. #define DEFAULTEXPANSIONFACTOR 0.06
  240.  
  241. /* see Type 1 Font Format book for explanations of these values */
  242. /* Note that we're currently doing nothing for minfeature and password. */
  243. struct blues_struct
  244. {
  245.     struct blues_struct *next;    /* ptr to next Blues structure in list */
  246.     int numBlueValues;    /* # of BlueValues in following array */
  247.     int BlueValues[NUMBLUEVALUES];
  248.     int numOtherBlues;    /* # of OtherBlues values in following array */
  249.     int OtherBlues[NUMOTHERBLUES];
  250.     int numFamilyBlues;    /* # of FamilyBlues values in following array */
  251.     int FamilyBlues[NUMFAMILYBLUES];
  252.     int numFamilyOtherBlues;/* # of FamilyOtherBlues values in  */
  253.     int FamilyOtherBlues[NUMFAMILYOTHERBLUES];    /* this array */
  254.     double BlueScale;
  255.     int BlueShift;
  256.     int BlueFuzz;
  257.     double StdHW;
  258.     double StdVW;
  259.     int numStemSnapH;    /* # of StemSnapH values in following array */
  260.     double StemSnapH[NUMSTEMSNAPH];
  261.     int numStemSnapV;    /* # of StemSnapV values in following array */
  262.     double StemSnapV[NUMSTEMSNAPV];
  263.     int ForceBold;
  264.     int LanguageGroup;
  265.     int RndStemUp;
  266.     int lenIV;
  267.     double ExpansionFactor;
  268. };
  269.  
  270. /* the alignment zone structure -- somewhat similar to the stem structure */
  271. /* see Adobe Type1 Font Format book about the terms used in this structure */
  272. struct alignmentzone
  273. {
  274.     int topzone;        /* TRUE if a topzone, FALSE if a bottom zone */
  275.     double bottomy, topy;    /* interval of this alignment zone */
  276. };
  277.  
  278.  
  279. /*********
  280.  * CLUTS.H
  281.  *********/
  282.  
  283. #define   KillCLUT(T)
  284. #define   CopyCLUT(T)                T
  285. #define   UniqueCLUT(T)
  286.  
  287.  
  288. /*********
  289.  * CURVES.H
  290.  *********/
  291.  
  292. #define   StepConic(R,xA,yA,xB,yB,xC,yC,r)      t1_StepConic(R,xA,yA,xB,yB,xC,yC,r)
  293. #define   StepBezier(R,xA,yA,xB,yB,xC,yC,xD,yD) t1_StepBezier(R,xA,yA,xB,yB,xC,yC,xD,yD)
  294.  
  295. #define   FlattenConic(xM,yM,xC,yC,r)        t1_StepConic(NULL,(fractpel)0,(fractpel)0,xM,yM,xC,yC,r)
  296. #define   FlattenBezier(xB,yB,xC,yC,xD,yD)   t1_StepBezier(NULL,(fractpel)0,(fractpel)0,xB,yB,xC,yC,xD,yD)
  297.  
  298.  
  299. /*********
  300.  * FONTFCN.H
  301.  *********/
  302.  
  303. /*     Definition of a PostScript FONT             */
  304. typedef struct ps_font
  305. {
  306.     char *vm_start;
  307.     psobj FontFileName;
  308.     psobj Subrs;
  309.     psdict *CharStringsP;
  310.     psdict *Private;
  311.     psdict *fontInfoP;
  312.     struct blues_struct *BluesP;
  313. } psfont;
  314.  
  315. /***================================================================***/
  316. /*  Return codes from scan_font                                       */
  317. /***================================================================***/
  318. #define SCAN_OK               0
  319. #define SCAN_FILE_EOF        -1
  320. #define SCAN_ERROR           -2
  321. #define SCAN_OUT_OF_MEMORY   -3
  322. #define SCAN_FILE_OPEN_ERROR -4
  323. #define SCAN_TRUE            -5
  324. #define SCAN_FALSE           -6
  325. #define SCAN_END             -7
  326.  
  327. /***================================================================***/
  328. /*  Name of FontInfo fields                                           */
  329. /***================================================================***/
  330.  
  331. #define FONTNAME 1
  332. #define PAINTTYPE 2
  333. #define FONTTYPENUM 3
  334. #define FONTMATRIX 4
  335. #define FONTBBOX   5
  336. #define UNIQUEID  6
  337. #define STROKEWIDTH  7
  338. #define VERSION     8
  339. #define NOTICE     9
  340. #define FULLNAME 10
  341. #define FAMILYNAME 11
  342. #define WEIGHT 12
  343. #define ITALICANGLE 13
  344. #define ISFIXEDPITCH  14
  345. #define UNDERLINEPOSITION 15
  346. #define UNDERLINETHICKNESS 16
  347. #define ENCODING 17
  348. /***================================================================***/
  349. /*  Name of Private values                                            */
  350. /***================================================================***/
  351. #define BLUEVALUES 1
  352. #define OTHERBLUES 2
  353. #define FAMILYBLUES 3
  354. #define FAMILYOTHERBLUES 4
  355. #define BLUESCALE 5
  356. #define BLUESHIFT 6
  357. #define BLUEFUZZ  7
  358. #define STDHW     8
  359. #define STDVW     9
  360. #define STEMSNAPH 10
  361. #define STEMSNAPV 11
  362. #define FORCEBOLD 12
  363. #define LANGUAGEGROUP 13
  364. #define LENIV     14
  365. #define RNDSTEMUP 15
  366. #define EXPANSIONFACTOR 16
  367.  
  368.  
  369. /*********
  370.  * FONTS.H
  371.  *********/
  372.  
  373. #define   CopyFont(f)     f
  374. #define   UniqueFont(f)   f
  375. #define   KillFont(f)
  376. #define   KillText(t)
  377. #define   CopyText(t)     t
  378. #define   I_DumpText(t)
  379. #define   CoerceText(t)   t
  380. #define   TextDelta(t,pt)
  381. #define   XformText(p,s)
  382. #define   GimeSpace()     FALSE
  383.  
  384. #define   TraceClose()
  385.  
  386.  
  387. /*********
  388.  * HINTS.H
  389.  *********/
  390.  
  391. #define   CloseHints(hintP)   t1_CloseHints(hintP)
  392. #define   ProcessHint(hP, currX, currY, hintP)   t1_ProcessHint((struct hintsegment *)hP, currX, currY, hintP)
  393. #define   ApplyContinuity(R)  t1_ApplyContinuity(R)
  394.  
  395.  
  396. /*********
  397.  * LINES.H
  398.  *********/
  399.  
  400. #define   StepLine(R,x1,y1,x2,y2)   t1_StepLine(R,x1,y1,x2,y2)
  401. #define   Bresenham(e,x1,y1,x2,y2)  t1_Bresenham(e,x1,y1,x2,y2)
  402.  
  403.  
  404. /*********
  405.  * OBJECTS.H
  406.  *********/
  407. #define   ON          (~0)    /* all bits on                                  */
  408. #ifndef FALSE
  409. #define   FALSE       0        /* handy zero value                             */
  410. #endif
  411. #ifndef TRUE
  412. #define   TRUE        1        /* handy non-zero value                         */
  413. #endif
  414. #ifndef MIN
  415. #define   MIN(a,b)    (((a)<(b)) ? a : b)
  416. #endif
  417. #ifndef MAX
  418. #define   MAX(a,b)    (((a)>(b)) ? a : b)
  419. #endif
  420. #ifndef ABS
  421. #define   ABS(a)      (((a)>=0)?(a):-(a))
  422. #endif
  423. #ifndef NULL
  424. #define NULL 0L
  425. #endif
  426.  
  427.  
  428. /*
  429.  * Basic TYPE1IMAGER Object Structure
  430.  *
  431.  * All TYPE1IMAGER objects which are available to the user have a common
  432.  * header.  This header is defined below:
  433.  */
  434. struct xobject
  435. {
  436.     char type;        /* encoded type of object                         */
  437.     unsigned char flag;    /* flag byte for temporary object characteristics */
  438.     short references;    /* count of pointers to this object (plus 1 for permanent) PNM */
  439. };
  440.  
  441.  
  442. /*
  443.  * The following define is an attempt to centralize the definition of the
  444.  * common xobject data shared by structures that are derived from the
  445.  * generic xobject structure. For example, the structure font, defined in
  446.  * fonts.shr :
  447.  *     struct font {
  448.  *            char type;
  449.  *            char flag;
  450.  *            int references;
  451.  *            ... other data types & structs ...
  452.  *            }
  453.  *
  454.  * would now be defined as:
  455.  *     struct font {
  456.  *            XOBJ_COMMON
  457.  *            ... other data types & structs ...
  458.  *            }
  459.  *
  460.  * Thus we have a better-structured inheritance mechanism. 3-26-91 PNM
  461.  */
  462. #define XOBJ_COMMON      char type; unsigned char flag; short references;
  463.  
  464.  
  465. /*
  466.  * Object Type Definitions
  467.  *
  468.  * These constants define the values which go in the 'type' field of
  469.  * an TYPE1IMAGER object structure:
  470.  */
  471. #define   INVALIDTYPE    0
  472. #define   FONTTYPE       1
  473. #define   REGIONTYPE     3
  474. #define   PICTURETYPE    4
  475. #define   SPACETYPE      5
  476. #define   LINESTYLETYPE  6
  477. #define   EDGETYPE       7
  478. #define   STROKEPATHTYPE 8
  479. #define   CLUTTYPE       9
  480.  
  481. /*
  482.  * Flag Byte Definitions
  483.  *
  484.  * Many programmers define flag bits as a mask (for example, 0x04), and
  485.  * test, set, and reset them as follows:
  486.  *         if ((flag & PERMANENT) != 0)
  487.  *         flag |= PERMANENT;
  488.  *         flag &= &inv.PERMANENT;
  489.  *
  490.  * I favor a style where the 'if' statement can ask a question:
  491.  *         if (ISPERMANENT(flag))
  492.  *         flag |= ISPERMANENT(ON);
  493.  *         flag &= &inv.ISPERMANENT(ON);
  494.  *
  495.  * This said, we now define two bit settings of the flag byte of the
  496.  * object.  "ISPERMANENT" will be set by the user, when he calls
  497.  * Permanent().  "ISIMMORTAL" will be used for compiled-in objects
  498.  * that we don't want the user to ever destroy.
  499.  */
  500. /*
  501.  * Flag bit definitions that apply to all objects are assigned
  502.  * starting with the least significant (0x01) bit.  Flag bit definitions
  503.  * specific to a certain object type are assigned starting with the
  504.  * most significant (0x80) bit.  We hope they never meet.
  505.  */
  506. #define   ISPATHTYPE(type)    ((type)&0x10)    /* all path segments have this bit on */
  507. #define   LINETYPE    (0+ISPATHTYPE(ON))
  508. #define   CONICTYPE   (1+ISPATHTYPE(ON))
  509. #define   BEZIERTYPE  (2+ISPATHTYPE(ON))
  510. #define   HINTTYPE    (3+ISPATHTYPE(ON))
  511.  
  512. #define   MOVETYPE    (5+ISPATHTYPE(ON))
  513. #define   TEXTTYPE    (6+ISPATHTYPE(ON))
  514.  
  515.  
  516. #define   ISPERMANENT(flag)   ((flag)&0x01)
  517. #define   ISIMMORTAL(flag)    ((flag)&0x02)
  518.  
  519.  
  520. /*
  521.  * PRESERVE() Macro
  522.  *
  523.  * Occasionally an TYPE1IMAGER operator is implemented by calling other
  524.  * TYPE1IMAGER operators.  For example, Arc2() calls Conic().  When we
  525.  * call more than one operator as a subroutine, we have to be careful
  526.  * of temporary objects.  A temporary object will be consumed by the
  527.  * subroutine operator and then is no longer available for the caller.
  528.  * This can be prevented simply by bumping a temporary object's reference
  529.  * count.
  530.  */
  531. #define   PRESERVE(obj)   if (!ISPERMANENT((obj)->flag)) \
  532.    (obj)->references++;
  533.  
  534.  
  535. /*
  536.  * TYPE1IMAGER Object Functions
  537.  *
  538.  * LONGCOPY() - Macro to Copy "long" Aligned Data
  539.  *
  540.  * Copying arbitrary bytes in C is a bit of a problem.  "strcpy" can't be
  541.  * used, because 0 bytes are special-cased.  Most environments have a
  542.  * routine "memcopy" or "bcopy" or "bytecopy" that copies memory containing
  543.  * zero bytes.  Sadly, there is no standard on the name of such a routine,
  544.  * which makes it impossible to write truely portable code to use it.
  545.  *
  546.  * It turns out that TYPE1IMAGER, when it wants to copy data, frequently
  547.  * knows that both the source and destination are aligned on "long"
  548.  * boundaries.  This allows us to copy by using "long *" pointers.  This
  549.  * is usually very efficient on almost all processors.  Frequently, it
  550.  * is more efficient than using general-purpose assembly language routines.
  551.  * So, we define a macro to do this in a portable way.  "dest" and "source"
  552.  * must be long-aligned, and "bytes" must be a multiple of "sizeof(long)":
  553.  */
  554. #define  LONGCOPY(dest,source,bytes) { \
  555.     register long *p1 = (long *)dest;  register long *p2 = (long *)source; \
  556.     register int count = (bytes) / sizeof(long); \
  557.     while (--count >= 0) *p1++ = *p2++; }
  558.  
  559.  
  560. /*
  561.  * FOLLOWING() - Macro to Point to the Data Following a Structure
  562.  *
  563.  * There are several places in TYPE1IMAGER where we will allocate variable
  564.  * data that belongs to a structure immediately after that structure.
  565.  * This is a performance technique, because it reduces the number of
  566.  * trips we have to take through xiMalloc() and xiFree().  It turns out C has
  567.  * a very convenient way to point past a structure--if 'p' is a pointer
  568.  * to a structure, 'p+1' is a pointer to the data after it.  This
  569.  * behavior of C is somewhat startling and somewhat hard to follow, if
  570.  * you are not used to it, so we define a macro to point to the data
  571.  * following a structure:
  572.  */
  573. #define   FOLLOWING(p)  ((p)+1)
  574.  
  575.  
  576. /*
  577.  * TYPECHECK() - Verify the Type of an Argument
  578.  *
  579.  * This macro tests the type of an argument.  If the test fails, it consumes
  580.  * any other arguments as necessary and causes the imbedding routine to
  581.  * return the value 'whenBAD'.
  582.  *
  583.  * Note that the consumeables list should be an argument list itself, for
  584.  * example (0) or (2,A,B).  See :hdref refid=consume. below.
  585.  */
  586. #define  TYPECHECK(name, obj, expect, whenBAD, consumables, rettype) { \
  587.     if (obj->type != expect) { \
  588.          (Consume)consumables; \
  589.          return((rettype)t1_TypeErr(name, (struct xobject *)obj, expect, (struct xobject *)whenBAD)); \
  590.     } \
  591. }
  592.  
  593.  
  594. /*
  595.  * ARGCHECK() - Perform an Arbitrary Check on an Argument
  596.  *
  597.  * This macro is a generalization of TYPECHECK to take an arbitrary
  598.  * predicate.  If the error occurs (i.e., the predicate is true), the
  599.  * arbitrary message 'msg' is returned.
  600.  */
  601. #define  ARGCHECK(test,msg,obj,whenBAD,consumables,rettype) { \
  602.     if (test) { \
  603.         (Consume)consumables; \
  604.         return((rettype)ArgErr(msg, obj, whenBAD)); \
  605.     } \
  606. }
  607.  
  608.  
  609. /*
  610.  * TYPENULLCHECK() - Extension of TYPECHECK() for NULL arguments
  611.  *
  612.  * Many routines allow NULLs to be passed as arguments.  'whenBAD' will
  613.  * be returned in this case, too.
  614.  */
  615. /* Changed use of Dup() below to Temporary(Copy()) because Dup() does not
  616.    necessarily return a Unique Copy anymore! 3-26-91 */
  617. #define  TYPENULLCHECK(name, obj, expect, whenBAD, consumables,rettype) \
  618.     if (obj == NULL) { \
  619.         (Consume)consumables; \
  620.         if (whenBAD != NULL && ISPERMANENT(whenBAD->flag)) \
  621.               return((rettype)Temporary(Copy(whenBAD))); \
  622.         else  return((rettype)whenBAD); \
  623.     } else { \
  624.         if (obj->type != expect) { \
  625.              (Consume)consumables; \
  626.              return((rettype)t1_TypeErr(name, (struct xobject *)obj, expect, (struct xobject *)whenBAD)); \
  627.         } \
  628.     }
  629.  
  630.  
  631. /*
  632.  * MAKECONSUME() - Create a "Consume"-type Macro
  633.  *
  634.  * Consuming an object means destroying it if it is not permanent.  This
  635.  * logic is so common to all the routines, that it is immortalized in this
  636.  * macro.  For example, ConsumePath(p) can be simply defined as
  637.  * MAKECONSUME(p,KillPath(p)).  In effect, this macro operates on a
  638.  * meta-level.
  639.  */
  640. #define  MAKECONSUME(obj,stmt)  { if (!ISPERMANENT(obj->flag)) stmt; }
  641.  
  642.  
  643. /*
  644.  * MAKEUNIQUE() - Create a "Unique"-type Macro
  645.  *
  646.  * Many routines are written to modify their arguments in place.  Thus,
  647.  * they want to insure that they duplicate an object if it is permanent.
  648.  * This is called making an object "unique".  For example, UniquePath(p)
  649.  * can be simply defined as MAKEUNIQUE(p,DupPath(p)).
  650.  */
  651. #define MAKEUNIQUE(obj,stmt) ( ( (obj)->references > 1 ) ? stmt : obj )
  652.  
  653. #define IfTrace0(condition,model)
  654. #define IfTrace1(condition,model,arg0)
  655. #define IfTrace2(condition,model,arg0,arg1)
  656. #define IfTrace3(condition,model,arg0,arg1,arg2)
  657. #define IfTrace4(condition,model,arg0,arg1,arg2,arg3)
  658. #define IfTrace5(condition,model,arg0,arg1,arg2,arg3,arg4)
  659. #define IfTrace6(condition,model,arg0,arg1,arg2,arg3,arg4,arg5)
  660.  
  661.  
  662. void Trace0();
  663. char *Trace1(), *Trace2(), *Trace3(), *Trace4(), *Trace5(), *Trace6();
  664.  
  665. extern char MustCheckArgs;
  666. extern char MustTraceCalls;
  667. extern char MustCrash;
  668. extern char InternalTrace;
  669. extern char LineIOTrace;
  670.  
  671. extern char ProcessHints;
  672.  
  673. extern char SaveFontPaths;
  674.  
  675. extern short CRASTERCompressionType;
  676.  
  677. extern char ConicDebug;
  678. extern char LineDebug;
  679. extern char RegionDebug;
  680. extern char PathDebug;
  681. extern char FontDebug;
  682. extern char SpaceDebug;
  683. extern char StrokeDebug;
  684. extern char MemoryDebug;
  685. extern char HintDebug;
  686. extern char ImageDebug;
  687. extern char OffPageDebug;
  688.  
  689. extern short CachedChars;
  690. extern short CachedFonts;
  691. extern int CacheBLimit;
  692. extern char Continuity;
  693.  
  694. /*
  695. We define other routines formatting parameters
  696. */
  697. #define    DumpArea(area)    t1_DumpArea(area)
  698. #define    DumpText(text)    t1_DumpText(text)
  699. #define    DumpEdges(e)      t1_DumpEdges(e)
  700.  
  701. #define   Permanent(obj)    t1_Permanent((struct xobject *)obj)
  702. #define   Temporary(obj)    t1_Temporary(obj)
  703. #define   Destroy(obj)      t1_Destroy((struct xobject *)obj)
  704. #define   Dup(obj)          t1_Dup((struct xobject *)obj)
  705. #define   Pragmatics(f,v)   t1_Pragmatics(f,v)
  706.  
  707. #define   Allocate(n,t,s)   t1_Allocate(n,(struct xobject *)t,s)
  708. #define   Free(obj)         t1_Free((struct xobject *)obj)
  709. #define   NonObjectFree(a)  xiFree(a)
  710. #define   Consume           t1_Consume
  711. #define   ArgErr(s,o,r)     t1_ArgErr(s,(struct xobject *)o,(struct xobject *)r)
  712. #define   TypeErr(n,o,e,r)  t1_TypeErr(n,(struct xobject *)o,e,(struct xobject *)r)
  713. #define   Copy(obj)         t1_Copy(obj)
  714. #define   Unique(obj)       t1_Unique((struct xobject *)obj)
  715.  
  716.  
  717. /*********
  718.  * SPACES.H
  719.  *********/
  720.  
  721. #define   USER                       t1_User
  722.  
  723. #define   Context(d,u)               t1_Context(d,u)
  724. #define   Rotate(o,d)                xiRotate((struct object *)o,d)
  725. #define   Scale(o,sx,sy)             t1_Scale((struct xobject *)o,sx,sy)
  726. #define   QuerySpace(S,f1,f2,f3,f4)  t1_QuerySpace(S,f1,f2,f3,f4)
  727. #define   Warp(s1,o,s2)              t1_Warp(s1,o,s2)
  728. #define   DeviceResolution           t1_DeviceResolution
  729. #define   CopySpace(s)               t1_CopySpace((struct XYspace *)s)
  730. #define   Xform(o,M)                 t1_Xform(o,M)
  731. #define   UnConvert(S,pt,xp,yp)      t1_UnConvert(S,pt,xp,yp)
  732. #define   MatrixMultiply(A,B,C)      t1_MMultiply(A,B,C)
  733. #define   MatrixInvert(A,B)          t1_MInvert(A,B)
  734. #define   PseudoSpace(S,M)           t1_PseudoSpace(S,M)
  735. #define   FindContext(M)             t1_FindContext(M)
  736.  
  737. /*
  738.  * Macros and Typedefs Provided to Other Modules
  739.  *
  740.  * Duplicating and Killing Spaces
  741.  *
  742.  * Destroying XYspaces is so simple we can do it with a
  743.  * macro:
  744.  */
  745. /*
  746.  * #define    KillSpace(s)     Free(s)
  747.  * Note - redefined KillSpace() to check references !
  748.  * 3-26-91 PNM
  749.  */
  750. #define KillSpace(s)  if ( (--(s->references) == 0) ||\
  751.                       ( (s->references == 1) && ISPERMANENT(s->flag) ) )\
  752.                         Free(s)
  753.  
  754. #define    ConsumeSpace(s)  MAKECONSUME(s,KillSpace(s))
  755. #define    UniqueSpace(s)   MAKEUNIQUE(s,CopySpace(s))
  756.  
  757. /*
  758.  * On the other hand, duplicating XYspaces is slightly more difficult
  759.  * because of the need to keep a unique ID in the space.
  760.  *
  761.  * Fixed Point Pel Representation
  762.  *
  763.  * We represent pel positions with fixed point numbers.  This does NOT
  764.  * mean integer, but truly means fixed point, with a certain number
  765.  * of binary digits (FRACTBITS) representing the fractional part of the
  766.  * pel.
  767.  */
  768. typedef short pel;            /* integer pel locations                        */
  769. typedef long fractpel;        /* fractional pel locations                     */
  770.  
  771. #define   FRACTBITS     16    /* number of fractional bits in 'fractpel'      */
  772.  
  773.  
  774. /*
  775.  * We define the following macros to convert from 'fractpel' to 'pel' and
  776.  * vice versa:
  777.  */
  778. #define   TOFRACTPEL(p)   (((fractpel)p)<<FRACTBITS)
  779. #define   FPHALF          (1<<(FRACTBITS-1))
  780. #define   NEARESTPEL(fp)  (((fp)+FPHALF)>>FRACTBITS)
  781. #define   FRACTFLOAT   (double)(1L<<FRACTBITS)
  782.  
  783.  
  784. /*
  785.  * Data Structures for Coordinate Spaces and Points
  786.  */
  787.  
  788. /*
  789.  * Matrices
  790.  *
  791.  * TYPE1IMAGER uses 2x2 transformation matrices.  We'll use C notation for
  792.  * such a matrix (M[2][2]), the first index being rows, the second columns.
  793.  */
  794.  
  795. /*
  796.  * The "doublematrix" Structure
  797.  *
  798.  * We frequently find it desirable to store both a matrix and its
  799.  * inverse.  We store these in a "doublematrix" structure.
  800.  */
  801. struct doublematrix
  802. {
  803.     double normal[2][2];
  804.     double inverse[2][2];
  805. };
  806.  
  807. /*
  808.  * The "XYspace" Structure
  809.  *
  810.  * The XYspace structure represents the XYspace object.
  811.  */
  812. struct XYspace
  813. {
  814.     XOBJ_COMMON                /* xobject common data define 3-26-91 PNM */
  815.                         /* type = SPACETYPE */
  816.  
  817.     void __stdargs (*convert) (struct fractpoint *pt, struct XYspace *S, double x, double y);
  818.                         /* calculate "fractpoint" X,Y from double X,Y */
  819.  
  820.     void __stdargs (*iconvert) (struct fractpoint *pt, struct XYspace *S, long x, long y);
  821.                         /* calculate "fractpoint" X,Y from int X,Y */
  822.  
  823.     fractpel __stdargs (*xconvert) (double cx, double cy, double x, double y);
  824.                         /* subroutine of convert */
  825.  
  826.     fractpel __stdargs (*yconvert) (double cx, double cy, double x, double y);
  827.                         /* subroutine of convert */
  828.  
  829.     fractpel __stdargs (*ixconvert) (fractpel cx, fractpel cy, long x, long y);
  830.                         /* subroutine of iconvert */
  831.  
  832.     fractpel __stdargs (*iyconvert) (fractpel cx, fractpel cy, long x, long y);
  833.                         /* subroutine of iconvert */
  834.  
  835.     int ID;                    /* unique identifier (used in font caching) */
  836.     unsigned char context;            /* device context of coordinate space */
  837.     struct doublematrix tofract;        /* xform to get to fractional pels */
  838.     fractpel itofract[2][2];        /* integer version of "tofract.normal" */
  839. };
  840.  
  841. #define    INVALIDID  0        /* no valid space will have this ID             */
  842.  
  843. /*
  844.  * The "fractpoint" Structure
  845.  *
  846.  * A fractional point is just a "fractpel" x and y:
  847.  */
  848. struct fractpoint
  849. {
  850.     fractpel x, y;
  851. };
  852.  
  853. #define  NULLCONTEXT   0
  854.  
  855.  
  856. /*********
  857.  * HINTS.C
  858.  * moved here from hints.c to deal with oldHint global variable
  859.  * declaration in HINTS.c (by moving into globals.c)
  860.  *********/
  861.  
  862. #define MAXLABEL 20
  863. struct oldhintstruct
  864. {
  865.     int inuse;
  866.     int computed;
  867.     struct fractpoint hint;
  868. };
  869.  
  870.  
  871. /*********
  872.  * PATHS.H
  873.  *********/
  874.  
  875.  
  876. #define    ConsumePath(p)    MAKECONSUME(p,KillPath(p))
  877. #define    UniquePath(p)     MAKEUNIQUE(p,CopyPath(p))
  878.  
  879. struct segment
  880. {
  881.     XOBJ_COMMON        /* xobject common data define 3-26-91 PNM             */
  882.     unsigned char size;    /* size of the structure                        */
  883.     unsigned char context;    /* index to device context                    */
  884.     struct segment *link;    /* pointer to next structure in linked list     */
  885.     struct segment *last;    /* pointer to last structure in list            */
  886.     struct fractpoint dest;    /* relative ending location of path segment   */
  887. };
  888.  
  889. #define   ISCLOSED(flag)   ((flag)&0x80)    /* subpath is closed               */
  890. #define   LASTCLOSED(flag) ((flag)&0x40)    /* last segment in closed subpath  */
  891.  
  892. /*
  893. NOTE: The ISCLOSED flag is set on the MOVETYPE segment before the
  894. subpath proper; the LASTCLOSED flag is set on the last segment (LINETYPE)
  895. in the subpath
  896.  
  897. We define the ISPATHANCHOR predicate to test that a path handle
  898. passed by the user is valid:
  899. */
  900.  
  901. #define   ISPATHANCHOR(p)  (ISPATHTYPE(p->type)&&p->last!=NULL)
  902.  
  903. /*
  904. For performance reasons, a user's "location" object is identical to
  905. a path whose only segment is a move segment.  We define a predicate
  906. to test for this case.  See also :hdref refid=location..
  907. */
  908.  
  909. #define   ISLOCATION(p)    ((p)->type == MOVETYPE && (p)->link == NULL)
  910.  
  911. struct conicsegment
  912. {
  913.     XOBJ_COMMON        /* xobject common data define 3-26-91 PNM        */
  914.     /* type = CONICTYPE                         */
  915.     unsigned char size;    /* as with any 'segment' type                   */
  916.     unsigned char context;    /* as with any 'segment' type                 */
  917.     struct segment *link;    /* as with any 'segment' type                   */
  918.     struct segment *last;    /* as with any 'segment' type                   */
  919.     struct fractpoint dest;    /* Ending point (C point)                    */
  920.     struct fractpoint M;    /* "midpoint" of conic explained above          */
  921.     double roundness;    /* explained above                              */
  922. };
  923.  
  924. struct beziersegment
  925. {
  926.     XOBJ_COMMON        /* xobject common data define 3-26-91 PNM       */
  927.     /* type = BEZIERTYPE                     */
  928.     unsigned char size;    /* as with any 'segment' type                   */
  929.     unsigned char context;    /* as with any 'segment' type                 */
  930.     struct segment *link;    /* as with any 'segment' type                   */
  931.     struct segment *last;    /* as with any 'segment' type                   */
  932.     struct fractpoint dest;    /* ending point (D)                          */
  933.     struct fractpoint B;    /* control point B                              */
  934.     struct fractpoint C;    /* control point C                              */
  935. };
  936.  
  937. struct hintsegment
  938. {
  939.     XOBJ_COMMON        /* xobject common data define 3-26-91 PNM      */
  940.     /* type = HINTTYPE                 */
  941.     unsigned char size;    /* size of the structure                        */
  942.     unsigned char context;    /* device context                             */
  943.     struct segment *link;    /* pointer to next structure in linked list     */
  944.     struct segment *last;    /* pointer to last structure in list            */
  945.     struct fractpoint dest;    /* ALWAYS 0,0                                 */
  946.     struct fractpoint ref;
  947.     struct fractpoint width;
  948.     char orientation;
  949.     char hinttype;
  950.     char adjusttype;
  951.     char direction;
  952.     int label;
  953. };
  954.  
  955. /*
  956. CONCAT links the 'p2' path chain on the end of the 'p1' chain.  (This macro
  957. is also used by the STROKES module.)
  958. */
  959. #define  CONCAT(p1, p2)  { \
  960.        p1->last->link = p2;     /* link p2 on end of p1                      */ \
  961.        p1->last = p2->last;    /* last of new is last of p2                  */ \
  962.        p2->last = NULL; }    /* only first segment has non-NULL "last"       */
  963.  
  964. #define   Loc(S,x,y)                   t1_Loc(S,(double)x,(double)y)
  965. #define   ILoc(S,x,y)                  t1_ILoc(S,x,y)
  966. #define   Line(P)                      t1_Line(P)
  967. #define   Join(p1,p2)                  t1_Join((struct segment *)p1,(struct segment *)p2)
  968. #define   ClosePath(p)                 t1_ClosePath(p,0)
  969. #define   CloseLastSubPath(p)          t1_ClosePath(p,1)
  970. #define   Conic(B,C,s)                 t1_Conic(B,C,(double)s)
  971. #define   RoundConic(M,C,r)            t1_RoundConic(M,C,(double)r)
  972. #define   ArcP3(S,P2,P3)               t1_ArcP3(S,P2,P3)
  973. #define   ArcCA(S,C,d)                 t1_ArcCA(S,C,(double)d)
  974. #define   Bezier(B,C,D)                t1_Bezier(B,C,D)
  975. #define   Hint(S,r,w,o,h,a,d,l)        t1_Hint(S,r,w,o,h,a,d,l)
  976. #define   Reverse(p)                   t1_Reverse(p)
  977. #define   ReverseSubPaths(p)           t1_ReverseSubPaths(p)
  978. #define   AddLoc(p1,p2)                t1_Join(p1,p2)
  979. #define   SubLoc(p1,p2)                t1_SubLoc(p1,p2)
  980. #define   DropSegment(p)               t1_DropSegment(p)
  981. #define   HeadSegment(p)               t1_HeadSegment(p)
  982. #define   QueryLoc(P,S,x,y)            t1_QueryLoc(P,S,x,y)
  983. #define   QueryPath(p,t,B,C,D,r)       t1_QueryPath(p,t,B,C,D,r)
  984. #define   QueryBounds(p,S,x1,y1,x2,y2)  t1_QueryBounds(p,S,x1,y1,x2,y2)
  985.  
  986. #define   CopyPath(p)             t1_CopyPath((struct segment *)p)
  987. #define   KillPath(p)             t1_KillPath((struct segment *)p)
  988. #define   PathTransform(p,m)      t1_PathXform(p,m)
  989. #define   PathDelta(p,pt)         t1_PathDelta((struct segment *)p,pt)
  990. #define   BoundingBox(h,w)        t1_BoundingBox(h,w)
  991. #define   PathSegment(t,x,y)      t1_PathSegment(t,(fractpel)x,(fractpel)y)
  992. #define   JoinSegment(b,t,x,y,a)  t1_JoinSegment(b,t,(fractpel)x,(fractpel)y,a)
  993. #define   Hypoteneuse(dx,dy)      t1_Hypoteneuse(dx,dy)
  994. #define   BoxPath(S,h,w)          t1_BoxPath(S,h,w)
  995.  
  996.  
  997. /*********
  998.  * PICTURES.H
  999.  *********/
  1000.  
  1001. #define    CopyPicture(p)         p
  1002. #define    UniquePicture(p)       p
  1003. #define    KillPicture(p)
  1004. #define    BegHandle(o,m)         o
  1005. #define    EndHandle(o,m)         o
  1006. #define    PictureBounds(P)       P
  1007.  
  1008. struct picture
  1009. {
  1010.     struct fractpoint origin;
  1011.     struct fractpoint ending;
  1012. };
  1013.  
  1014.  
  1015. /*********
  1016.  * REGIONS.H
  1017.  *********/
  1018.  
  1019.  
  1020. /*
  1021.  * GOING_TO() - Macro Predicate Needed for Changing Direction, Etc.
  1022.  *
  1023.  * The actual generation of run end lists (edge boundaries) is left
  1024.  * to the low level rasterizing modules, LINES and CURVES.  There
  1025.  * are some global region-type
  1026.  * questions that occur when doing a low-level
  1027.  * rasterization:
  1028.  *
  1029.  * Did we just change direction in Y and therefore need to start
  1030.  * a new edge?
  1031.  * Did we run out of allocated edge space?
  1032.  * Do the minimum or maximum X values for the current edge need
  1033.  * updating?
  1034.  *
  1035.  * In general the REGIONS is not smart enough to answer those questions
  1036.  * itself.  (For example, determining if and when a curve changes direction
  1037.  * may need detailed curve knowledge.)  Yet, this must be done efficiently.
  1038.  * We provide a macro "GOING_TO" where the invoker tells us where it is
  1039.  * heading for (x2,y2), plus where it is now (x1,y1), plus the current
  1040.  * region under construction, and the macro answers the questions above.
  1041.  */
  1042. #define GOING_TO(R, x1, y1, x2, y2, dy) { \
  1043.    if (dy < 0) { \
  1044.       if (R->lastdy >= 0) \
  1045.           ChangeDirection(CD_CONTINUE, R, x1, y1, dy); \
  1046.       if (y2 < R->edgeYstop) \
  1047.           MoreWorkArea(R, x1, y1, x2, y2); \
  1048.    } \
  1049.    else if (dy > 0) { \
  1050.       if (R->lastdy <= 0) \
  1051.           ChangeDirection(CD_CONTINUE, R, x1, y1, dy); \
  1052.       if (y2 > R->edgeYstop) \
  1053.           MoreWorkArea(R, x1, y1, x2, y2); \
  1054.    } \
  1055.    else /* dy == 0 */ ChangeDirection(CD_CONTINUE, R, x1, y1, dy); \
  1056.    if (x2 < R->edgexmin) R->edgexmin = x2; \
  1057.    else if (x2 > R->edgexmax) R->edgexmax = x2; \
  1058. }
  1059.  
  1060. #include <limits.h>
  1061. #ifdef SHRT_MIN
  1062. #define MINPEL SHRT_MIN
  1063. #else
  1064. #define MINPEL ((pel)(-1<<(8*sizeof(pel)-1)))  /* smallest value fitting in a pel */
  1065. #endif
  1066. #ifdef SHRT_MAX
  1067. #define MAXPEL SHRT_MAX
  1068. #else
  1069. #define MAXPEL ((pel)((1<<(8*sizeof(pel)-1))-1))/* largest value fitting in a pel */
  1070. #endif
  1071.  
  1072.  
  1073. /*
  1074.  * The "Unique"-type macro is different (unique?) for regions, because some
  1075.  * regions structures are shared among several objects, and might have
  1076.  * to be made unique for that reason (i.e., references > 1).
  1077.  */
  1078. #define    ConsumeRegion(R)   MAKECONSUME(R,KillRegion(R))
  1079. #define    UniqueRegion(R)    MAKEUNIQUE(R,CopyRegion(R))
  1080.  
  1081.  
  1082. /*
  1083.  * The "region" Structure
  1084.  *
  1085.  * The region structure is an anchor for a linked list of "edgelist"
  1086.  * structures (see :hdref refid=edgelist..).  It also summarizes the
  1087.  * information in the edgelist structures (for example, the bounding
  1088.  * box of the region).  And, it contains scratch areas used during
  1089.  * the creation of a region.
  1090.  */
  1091. struct region
  1092. {
  1093.     XOBJ_COMMON                        /* xobject common data define 3-26-91 PNM    */
  1094.                                     /* type = REGIONTYPE                         */
  1095.     struct fractpoint origin;        /* beginning handle:  X,Y origin of region      */
  1096.     struct fractpoint ending;        /* ending handle:  X,Y change after painting region */
  1097.     pel xmin, ymin;                    /* minimum X,Y of region                        */
  1098.     pel xmax, ymax;                    /* maximum X,Y of region                        */
  1099.     struct edgelist *anchor;        /* list of edges that bound the region      */
  1100.     struct picture *thresholded;    /* region defined by thresholded picture*/
  1101.  
  1102.     /*
  1103.      * Note that the ending handle and the bounding box values are stored
  1104.      * relative to 'origin'.
  1105.      *
  1106.      * The above elements describe a region.  The following elements are
  1107.      * scratchpad areas used while the region is being built:
  1108.      */
  1109.     fractpel lastdy;                /* direction of last segment */
  1110.     fractpel firstx, firsty;            /* starting point of current edge */
  1111.     fractpel edgexmin, edgexmax;            /* x extent of current edge */
  1112.     struct edgelist *lastedge;
  1113.     struct edgelist *firstedge;            /* last and first edges in subpath */
  1114.     pel *edge;                    /* pointer to array of X values for edge */
  1115.     fractpel edgeYstop;                /* Y value where 'edges' array ends */
  1116.     void (*newedgefcn) (struct region *,
  1117.             fractpel, fractpel, fractpel,
  1118.             fractpel, int);            /* function to use when building a new edge */
  1119.     struct strokeinfo *strokeinfo;            /* scratchpad info during stroking only */
  1120. };
  1121.  
  1122.  
  1123. /*
  1124.  * The ISCOMPLEMENT flag indicates the region is reversed--it is the
  1125.  * "outside" of the nominal region.
  1126.  */
  1127. #define   ISCOMPLEMENT(flag)   ((flag)&0x80)
  1128.  
  1129.  
  1130. /*
  1131.  * The ISJUMBLED flag indicates the region is not sorted top-to-bottom.
  1132.  */
  1133. #define   ISJUMBLED(flag)      ((flag)&0x40)
  1134.  
  1135.  
  1136. /*
  1137.  * The ISINFINITE flag allows a quick check for an INFINITE region, which
  1138.  * is frequently intersected.
  1139.  */
  1140. #define   ISINFINITE(flag)     ((flag)&0x20)
  1141.  
  1142.  
  1143. /*
  1144.  * The ISRECTANGULAR flag tells us if a region is a rectangle.  We don't
  1145.  * always notice rectangles--if this flag is set, the region definitely
  1146.  * is a rectangle, but some rectangular regions will not have the flag
  1147.  * set.  The flag is used to optimize some paths.
  1148.  */
  1149. #define   ISRECTANGULAR(flag)  ((flag)&0x08)
  1150.  
  1151.  
  1152. #define  EmptyRegion   t1_EmptyRegion
  1153.  
  1154.  
  1155. /*
  1156.  * The "edgelist" Structure
  1157.  *
  1158.  * Regions are represented by a linked list of 'edgelist' structures.
  1159.  * When a region is complete, the structures are paired, one for the
  1160.  * left and one for the right edge.  While a region is being built,
  1161.  * this rule may be violated temporarily.
  1162.  *
  1163.  * An 'edgelist' structure contains the X values for a given span
  1164.  * of Y values.  The (X,Y) pairs define an edge.  We use the crack
  1165.  * and edge coordinate system, so that integer values of X and Y
  1166.  * go between pels.  The edge is defined between the minimum Y and
  1167.  * maximum Y.
  1168.  *
  1169.  * The linked list is kept sorted from top to bottom, that is, in
  1170.  * increasing y.  Also, if 'e1' is an edgelist structure and 'e2' is the
  1171.  * next one in the list, they must have exactly the same ymin,ymax values
  1172.  * or be totally disjoint.  These two requirements mean that if e2's ymin
  1173.  * is less than e1's ymax, it must be exactly equal to e1's ymin.  A
  1174.  * sublist of structures with identical ymin and ymax values is called a
  1175.  * 'swath'.
  1176.  *
  1177.  * In addition, edgelist structures are separately linked together based
  1178.  * on what subpath originally created them; each subpath is kept as a
  1179.  * separate circular linked list.  This information is ignored unless
  1180.  * continuity checking is invoked.  See subpath for a
  1181.  * complete description of this.
  1182.  */
  1183. struct edgelist
  1184. {
  1185.     XOBJ_COMMON                    /* xobject common data define 3-26-91 PNM */
  1186.                                 /* type = EDGETYPE */
  1187.     struct edgelist *link;        /* pointer to next in linked list */
  1188.     struct edgelist *subpath;    /* informational link for "same subpath" */
  1189.     pel xmin, xmax;                /* range of edge in X */
  1190.     pel ymin, ymax;                /* range of edge in Y */
  1191.     pel *xvalues;                /* pointer to ymax-ymin X values */
  1192. };
  1193.  
  1194.  
  1195. /*
  1196.  * The end of the list is marked by either "link" being NULL, or by
  1197.  * ymin == ymax.  We define the VALIDEDGE
  1198.  * predicate to test for the opposite of these conditions:
  1199.  */
  1200. #define   VALIDEDGE(p)    ((p)!=NULL&&(p)->ymin<(p)->ymax)
  1201.  
  1202.  
  1203. /*
  1204.  * The "edgelist" structure follows the convention of TYPE1IMAGER user
  1205.  * objects, having a type field and a flag field as the first two
  1206.  * elements.  However, the user never sees "edgelist" structures
  1207.  * directly; he is given handles to "region" structures only.
  1208.  *
  1209.  * By having a type field, we can use the "copy" feature of Allocate()
  1210.  * to duplicate edge lists quickly.
  1211.  *
  1212.  * We also define two flag bits for this structure.  The ISDOWN bit is set
  1213.  * if the edge is going in the direction of increasing Y. The ISAMBIGUOUS
  1214.  * bit is set if the edge is identical to its neighbor (edge->link); such
  1215.  * edges may be "left" when they should be "right", or vice versa,
  1216.  * unnecessarily confusing the continuity checking logic.  The FixSubPaths()
  1217.  * routine in HINTS will swap ambiguous edges if that avoids crossing edges;
  1218.  * see fixsubp.
  1219.  */
  1220. #define   ISDOWN(f)       ((f)&0x80)
  1221. #define   ISAMBIGUOUS(f)  ((f)&0x40)
  1222.  
  1223.  
  1224. /*
  1225.  * Interior() rule enumerations:
  1226.  */
  1227. #define   WINDINGRULE -2
  1228. #define   EVENODDRULE -3
  1229.  
  1230. #define   CONTINUITY  0x80    /* can be added to above rules; e.g. WINDINGRULE+CONTINUITY */
  1231. #define   Interior(p,rule)        t1_Interior(p,rule)
  1232. #define   Union(a1,a2)            t1_Union(a1,a2)
  1233. #define   Intersect(a1,a2)        t1_Intersect(a1,a2)
  1234. #define   Complement(area)        t1_Complement(area)
  1235. #define   Overlap(a1,a2)          t1_OverLap(a1,a2)
  1236.  
  1237. #define   ChangeDirection(type,R,x,y,dy)  t1_ChangeDirection(type,R,x,y,dy)
  1238. #define   CD_FIRST         -1    /* enumeration of ChangeDirection type       */
  1239. #define   CD_CONTINUE       0    /* enumeration of ChangeDirection type        */
  1240. #define   CD_LAST           1    /* enumeration of ChangeDirection type        */
  1241. #define    MoreWorkArea(R,x1,y1,x2,y2)     t1_MoreWorkArea(R,x1,y1,x2,y2)
  1242. #define    KillRegion(area)   t1_KillRegion((struct region *)area)
  1243. #define    CopyRegion(area)   t1_CopyRegion((struct region *)area)
  1244. #define    BoxClip(R,xmin,ymin,xmax,ymax)  t1_BoxClip(R,xmin,ymin,xmax,ymax)
  1245. #define    SortSwath(a,p,f)   t1_SortSwath(a,p,f)
  1246. #define    SwathUnion(b,e)    t1_SwathUnion(b,e)
  1247. #define    RegionBounds(r)    t1_RegionBounds((struct region *)r)
  1248. #define    CoerceRegion(p)    t1_CoerceRegion(p)
  1249. #define    MoveEdges(R,dx,dy) t1_MoveEdges(R,dx,dy)
  1250. #define    UnJumble(R)        t1_UnJumble(R)
  1251.  
  1252.  
  1253. /*********
  1254.  * STROKES.H
  1255.  *********/
  1256.  
  1257. #define   CopyLineStyle(s)    s
  1258. #define   CopyStrokePath(p)   p
  1259. #define   KillStrokePath(p)
  1260. #define   KillLineStyle(s)
  1261. #define   CoercePath(sp)      sp
  1262. #define   DoStroke(sp)        sp
  1263.  
  1264.  
  1265. /*********
  1266.  * T1IMAGER.H
  1267.  *********/
  1268. typedef pointer xobject;
  1269. typedef pointer location;
  1270. typedef pointer path;
  1271. typedef pointer region;
  1272. typedef pointer XYspace;
  1273. /*
  1274. Here are some TYPE1IMAGER functions that are defined in terms of others:
  1275. */
  1276.  
  1277. #define   t1_AddLoc(p1,p2)    t1_Join(p1,p2)
  1278.  
  1279. #ifndef   NONAMES
  1280. /*
  1281. Define the simple form of all the subroutine names:
  1282. */
  1283. #define   Bezier(B,C,D)      t1_Bezier(B,C,D)
  1284. #define   ClosePath(p)       t1_ClosePath(p,0)
  1285. #define   Complement(area)   t1_Complement(area)
  1286. #define   HeadSegment(p)     t1_HeadSegment(p)
  1287. #define   Interior(p,rule)   t1_Interior(p,rule)
  1288. #define   Line(P)            t1_Line(P)
  1289. #define   Phantom(o)         t1_Phantom((struct xobject *)o)
  1290. #define   Loc(S,x,y)         t1_Loc(S,(double)x,(double)y)
  1291. #define   Snap(o)            t1_Snap((struct segment *)o)
  1292. #define   Transform(o,cxx,cyx,cxy,cyy)  t1_Transform(o,(double)cxx,(double)cyx,\
  1293.     (double)cxy,(double)cyy)
  1294.  
  1295. #endif
  1296.  
  1297. #define   WINDINGRULE -2
  1298. #define   EVENODDRULE -3
  1299.  
  1300. #define   CONTINUITY  0x80    /* can be added to above rules; e.g. WINDINGRULE+CONTINUITY */
  1301.  
  1302. /*
  1303.  * Generic null object definition:
  1304.  */
  1305. #define    NULLOBJECT   ((xobject)NULL)
  1306.  
  1307. /*
  1308.  * Null path definition:
  1309.  */
  1310. #define    NULLPATH     NULLOBJECT
  1311.  
  1312. #define    NULLREGION   NULLOBJECT
  1313.  
  1314. #define    FF_PARSE_ERROR  5
  1315. #define    FF_PATH         1
  1316.  
  1317.  
  1318. /*********
  1319.  * T1INTF.H
  1320.  *********/
  1321.  
  1322.  
  1323. #define FIRSTCOL  32
  1324.  
  1325. struct type1font
  1326. {
  1327.     CharInfoPtr pDefault;
  1328.     CharInfoRec glyphs[256 - FIRSTCOL];
  1329. };
  1330.  
  1331.  
  1332. /*********
  1333.  * TOKEN.H
  1334.  *********/
  1335. /* Special characters */
  1336. #define CONTROL_C           (3)
  1337.  
  1338. /* Token type codes */
  1339. #define TOKEN_INVALID       (-3)
  1340. #define TOKEN_BREAK         (-2)
  1341. #define TOKEN_EOF           (-1)
  1342. #define TOKEN_NONE          (0)
  1343. #define TOKEN_LEFT_PAREN    (1)
  1344. #define TOKEN_RIGHT_PAREN   (2)
  1345. #define TOKEN_LEFT_ANGLE    (3)
  1346. #define TOKEN_RIGHT_ANGLE   (4)
  1347. #define TOKEN_LEFT_BRACE    (5)
  1348. #define TOKEN_RIGHT_BRACE   (6)
  1349. #define TOKEN_LEFT_BRACKET  (7)
  1350. #define TOKEN_RIGHT_BRACKET (8)
  1351. #define TOKEN_NAME          (9)
  1352. #define TOKEN_LITERAL_NAME  (10)
  1353. #define TOKEN_INTEGER       (11)
  1354. #define TOKEN_REAL          (12)
  1355. #define TOKEN_RADIX_NUMBER  (13)
  1356. #define TOKEN_HEX_STRING    (14)
  1357. #define TOKEN_STRING        (15)
  1358. #define TOKEN_IMMED_NAME    (16)
  1359.  
  1360.  
  1361. /*
  1362.  * -------------------------------------------------------------------------
  1363.  * Globals shared  -- (everyone else KEEP YOUR MITTS OFF THEM!)
  1364.  * -------------------------------------------------------------------------
  1365.  */
  1366.  
  1367. /* These variables are set by the caller */
  1368. extern char *tokenStartP;    /* Pointer to token buffer in VM */
  1369. extern char *tokenMaxP;        /* Pointer to end of VM we may use + 1 */
  1370.  
  1371. /* These variables are set by P_TOKEN */
  1372. extern int tokenLength;        /* Characters in token */
  1373. extern boolean tokenTooLong;    /* Token too long for space available */
  1374. extern int tokenType;        /* Type of token identified */
  1375. extern psvalue tokenValue;    /* Token value */
  1376.  
  1377.  
  1378. /*********
  1379.  * TRIG.H
  1380.  *********/
  1381. #ifndef PI
  1382. #define PI  3.14159265358979323846
  1383. #endif
  1384.  
  1385. #define   DegreeCos(d)    (cos((PI / 180) * d))
  1386. #define   DegreeSin(d)    (sin((PI / 180) * d))
  1387.  
  1388.  
  1389.  
  1390.  
  1391.  
  1392. /**********************
  1393.  ***** Prototypes *****
  1394.  **********************/
  1395.  
  1396.  
  1397. /**
  1398.  * arith.c
  1399.  **/
  1400. fractpel FPmult(fractpel u, fractpel v);
  1401.  
  1402.  
  1403. /**
  1404.  * curves.c
  1405.  **/
  1406. struct segment *StepBezier(struct region *R, fractpel xA, fractpel yA, fractpel xB, fractpel yB, fractpel xC, fractpel yC, fractpel xD, fractpel yD);
  1407.  
  1408.  
  1409. /**
  1410.  * fontfcn.c
  1411.  **/
  1412. int SearchDictName(psdict *dictP, psobj *keyP);
  1413. boolean initFont(int cnt);
  1414. int readFont(char *env);
  1415. xobject fontfcnB(struct XYspace *S, unsigned char *code, int *lenP, int *mode);
  1416. Bool fontfcnA(char *env, int *mode);
  1417. void QueryFontLib(char *env, char *infoName, pointer infoValue, int *rcodeP);
  1418.  
  1419.  
  1420. /**
  1421.  * hints.c
  1422.  **/
  1423. void InitHints(void);
  1424. void CloseHints(struct fractpoint *hintP);
  1425. void t1_ProcessHint(struct hintsegment *hP, fractpel currX, fractpel currY, struct fractpoint *hintP);
  1426. void ApplyContinuity(struct region *R);
  1427.  
  1428.  
  1429. /**
  1430.  * lines.c
  1431.  **/
  1432. void StepLine(struct region *R, fractpel x1, fractpel y1, fractpel x2, fractpel y2);
  1433. void Bresenham(pel *edgeP, fractpel x1, fractpel y1, fractpel x2, fractpel y2);
  1434.  
  1435.  
  1436. /**
  1437.  * objects
  1438.  **/
  1439. struct xobject *t1_Permanent(struct xobject *obj);
  1440. struct xobject *t1_Temporary(struct xobject *obj);
  1441. struct xobject *t1_Destroy(struct xobject *obj);
  1442. struct xobject *t1_Dup(struct xobject *obj);
  1443.  
  1444. void FatalError(char *line);
  1445. #define t1_abort(line) FatalError(line)
  1446.  
  1447. void Pragmatics(char *username, int value);
  1448. char *ErrorMsg(void);
  1449. struct xobject *t1_Allocate(int size, struct xobject *template, int extra);
  1450. void t1_Free(struct xobject *obj);
  1451. void Consume(int n, struct xobject *obj1, struct xobject *obj2, struct xobject *obj3);
  1452. struct xobject *t1_ArgErr(char *string, struct xobject *obj, struct xobject *ret);
  1453. struct xobject *t1_TypeErr(char *name, struct xobject *obj, int expect, struct xobject *ret);
  1454. struct xobject *t1_Copy(struct xobject *obj);
  1455. struct xobject *t1_Unique(struct xobject *obj);
  1456.  
  1457.  
  1458. /**
  1459.  * paths.c
  1460.  **/
  1461. struct segment *t1_Loc(struct XYspace *S, double x, double y);
  1462. struct segment *ILoc(struct XYspace *S, int x, int y);
  1463. struct segment *Line(struct segment *P);
  1464. struct segment *t1_Join(struct segment *p1, struct segment *p2);
  1465. struct segment *t1_ClosePath(struct segment *p0, int lastonly);
  1466. struct beziersegment *Bezier(struct segment *B,    struct segment *C, struct segment *D);
  1467. struct hintsegment *Hint(struct XYspace *S, double ref, double width, char orientation, char hinttype, char adjusttype, char direction, int label);
  1468. struct segment *Reverse(struct segment *p);
  1469. struct segment *ReverseSubPaths(struct segment *p);
  1470. struct segment *SubLoc(struct segment *p1, struct segment *p2);
  1471. struct segment *DropSegment(struct segment *path);
  1472. struct segment *HeadSegment(struct segment *path);
  1473. void QueryLoc(struct segment *P, struct XYspace *S, double *xP, double *yP);
  1474. void QueryPath(struct segment *path, int *typeP, struct segment **Bp, struct segment **Cp, struct segment **Dp, double *fP);
  1475. void QueryBounds(struct segment *p0, struct XYspace *S, double *xminP, double *yminP, double *xmaxP, double *ymaxP);
  1476.  
  1477. struct segment *t1_CopyPath(struct segment *p0);
  1478. void t1_KillPath(struct segment *p);
  1479. struct segment *PathTransform(struct segment *p0, struct XYspace *S);
  1480. void t1_PathDelta(struct segment *p, struct fractpoint *pt);
  1481. struct segment *BoundingBox(pel h, pel w);
  1482. struct segment *t1_PathSegment(int type, fractpel x, fractpel y);
  1483. struct segment *t1_JoinSegment(struct segment *before, int type, fractpel x, fractpel y, struct segment *after);
  1484. struct segment *BoxPath(struct XYspace *S, int h, int w);
  1485.  
  1486.  
  1487. /**
  1488.  * regions.c
  1489.  **/
  1490. struct region *Interior(struct segment *p, int fillrule);
  1491.  
  1492. void MoreWorkArea(struct region *R, fractpel x1, fractpel y1, fractpel x2, fractpel y2);
  1493. void t1_KillRegion(struct region *area);
  1494. struct region *t1_CopyRegion(struct region *area);
  1495. struct region *BoxClip(struct region *R, pel xmin, pel ymin, pel xmax, pel ymax);
  1496. struct edgelist *SortSwath(struct edgelist *anchor, struct edgelist *edge, struct edgelist *(*swathfcn) (struct edgelist *, struct edgelist *));
  1497. struct edgelist *SwathUnion(struct edgelist *before0, struct edgelist *edge);
  1498. struct segment *t1_RegionBounds(struct region *R);
  1499. struct region *CoerceRegion(struct textpath *tp);
  1500. void MoveEdges(struct region *R, fractpel dx, fractpel dy);
  1501. void UnJumble(struct region *region);
  1502.  
  1503. void ChangeDirection(int type, struct region *R, fractpel x, fractpel y, fractpel dy);
  1504. void DumpArea(struct region *area);
  1505. void DumpEdges(struct edgelist *edges);
  1506.  
  1507.  
  1508. /**
  1509.  * scanfont.c
  1510.  **/
  1511. boolean Init_BuiltInEncoding(void);
  1512. psobj *GetType1CharString(psfont *fontP, unsigned char code);
  1513. int scan_font(psfont *FontP);
  1514.  
  1515.  
  1516. /**
  1517.  * spaces.c
  1518.  **/
  1519. struct XYspace *t1_CopySpace(struct XYspace *S);
  1520. int FindContext(double M[2][2]);
  1521. struct XYspace *Context(pointer device, double units);
  1522. void UnConvert(struct XYspace *S, struct fractpoint *pt, double *xp, double *yp);
  1523. struct xobject *t1_Xform(struct xobject *obj, double M[2][2]);
  1524. struct xobject *t1_Transform(struct xobject *obj, double cxx, double cyx, double cxy, double cyy);
  1525. struct xobject *t1_Scale(struct xobject *obj, double sx, double sy);
  1526. struct xobject *xiRotate(struct xobject *obj, double degrees);
  1527. void PseudoSpace(struct XYspace *S, double M[2][2]);
  1528. void MatrixMultiply(double A[2][2], double B[2][2], double C[2][2]);
  1529. void MatrixInvert(double M[2][2], double Mprime[2][2]);
  1530. void InitSpaces(void);
  1531. void QuerySpace(struct XYspace *S, double *cxxP, double *cyxP, double *cxyP, double *cyyP);
  1532.  
  1533.  
  1534. /**
  1535.  * t1funcs.c
  1536.  **/
  1537. int MyType1OpenScalable(FontPtr *ppFont, char *fileName, FontScalablePtr vals);
  1538. int MyType1SetTransform(FontPtr pFont, FontScalablePtr vals);
  1539. int MyType1GetGlyphs(FontPtr pFont, int i, CharInfoPtr *returnglyph);
  1540. void MyType1CloseFont(FontPtr pFont);
  1541.  
  1542.  
  1543. /**
  1544.  * t1info.c (replaced by amishinfo.c)
  1545.  **/
  1546. void T1FillFontInfo(FontPtr pFont, FontScalablePtr Vals, char *Filename, char *Fontname);
  1547.  
  1548.  
  1549. /**
  1550.  * t1io.c
  1551.  **/
  1552. F_FILE *T1Open(char *fn, char *mode);
  1553. int T1Getc(F_FILE *f);
  1554. int T1Ungetc(int c, F_FILE *f);
  1555. int T1Read(char *buffP, int size, int n, F_FILE *f);
  1556. int T1Close(F_FILE *f);
  1557. void __asm T1eexec(register __a0 F_FILE *f);
  1558.  
  1559.  
  1560. /**
  1561.  * t1malloc.c
  1562.  **/
  1563. void xiFree(void *addr);
  1564. char *xiMalloc(unsigned int size);
  1565. void addmemory(long size);
  1566. void delmemory(void);
  1567.  
  1568. void addmemory2(long size);
  1569. void delmemory2(void);
  1570. char *Xalloc(int size);
  1571. void Xfree(char *p);
  1572.  
  1573.  
  1574. /**
  1575.  * t1snap.c
  1576.  **/
  1577. struct segment *t1_Phantom(struct xobject *obj);
  1578. struct xobject *t1_Snap(struct segment *p);
  1579.  
  1580.  
  1581. /**
  1582.  * token.c
  1583.  **/
  1584. void scan_token(psobj *inputP);
  1585.  
  1586.  
  1587. /**
  1588.  * type1.c
  1589.  **/
  1590. struct xobject *Type1Char(psfont *env, struct XYspace *S, psobj *charstrP, psobj *subrsP, psobj *osubrsP, struct blues_struct *bluesP, int *modeP);
  1591.  
  1592.  
  1593. /**
  1594.  * util.c
  1595.  **/
  1596. boolean vm_init(int cnt);
  1597. void free_vm(void);
  1598. char *vm_alloc(int bytes);
  1599. void objFormatInteger(psobj *objP, int value);
  1600. void objFormatReal(psobj *objP, double value);
  1601. void objFormatBoolean(psobj *objP, boolean value);
  1602. void objFormatEncoding(psobj *objP, int length, psobj *valueP);
  1603. void objFormatArray(psobj *objP, int length, psobj *valueP);
  1604. void objFormatString(psobj *objP, int length, char *valueP);
  1605. void objFormatName(psobj *objP, int length, char *valueP);
  1606. void objFormatFile(psobj *objP, F_FILE *valueP);
  1607.  
  1608.  
  1609. /**
  1610.  * readfont.c
  1611.  **/
  1612. int readfont(char *filename, char **pfbuf, int *pfbuflen);
  1613. void freefont(char *fbuf);
  1614.